package servlets;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import managers.EntityManagerAux;

/**
 * Servlet implementation class AddPropietary
 * Servlet pour ajouter les propietaires.
 */
public class AddPropietary extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddPropietary() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    @EJB EntityManagerAux mng;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String boss = request.getParameter("boss");
		String mail = request.getParameter("mail");
		String name = request.getParameter("name");
		String pass = request.getParameter("pass");
		String phone = request.getParameter("phone");
		String surname = request.getParameter("surname");
		
		String goTo="";
		
		if(!boss.isEmpty() && !mail.isEmpty() && !name.isEmpty() && !pass.isEmpty() && !phone.isEmpty() && !surname.isEmpty()) {
			mng.addPropietary(boss, mail, name, pass, phone, surname);
			goTo="Succes.jsp";
			request.getRequestDispatcher(goTo).forward(request, response);
		} 
		else {
			System.err.println("Error, null");
			goTo = "Error.jsp"; //Error, at least one field is null
			request.getRequestDispatcher(goTo).forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
